package com.njtoyo.taxi.admin.rest.controller.business.driver;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.QuerySpecialRewardRuleDetailPresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.QuerySpecialRewardRuleListPresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.QuerySpecialRewardRulePickRidePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.*;
import com.njtoyo.taxi.admin.service.business.driver.DriverSpecialReward;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("business/driver-special-reward")
@Api(tags = {"司机大红包"})
public class DriverSpecialRewardController {
    @Autowired
    private DriverSpecialReward driverSpecialReward;

    @PostMapping("/rule")
    @ApiOperation(value = "新增司机大红包规则", notes = "新增司机大红包规则，权限：driver_special_reward_rule_add")
    @PermissionScope(names = {"driver_special_reward_rule_add"})
    RestResult<Boolean> createRule(@Valid @RequestBody CreateSpecialRewardRuleWrapper wrapper) {
        return driverSpecialReward.createRule(wrapper);
    }

    @PatchMapping("/rule/{id}")
    @ApiOperation(value = "修改司机大红包规则", notes = "修改司机大红包规则，权限：driver_special_reward_rule_update")
    @PermissionScope(names = {"driver_special_reward_rule_update"})
    RestResult<Boolean> updateRule(@PathVariable("id") Long id, @Valid @RequestBody UpdateSpecialRewardRuleWrapper wrapper) {
        return driverSpecialReward.updateRule(id, wrapper);
    }

    @GetMapping("/rule")
    @ApiOperation(value = "司机大红包规则列表", notes = "司机大红包规则列表，权限：driver_special_reward_rule_list")
    @PermissionScope(names = {"driver_special_reward_rule_list"})
    RestResult<IPage<QuerySpecialRewardRuleListPresenter>> getRuleList(QuerySpecialRewardRuleListWrapper wrapper) {
        return driverSpecialReward.getRuleList(wrapper);

    }

    @GetMapping("/rule/{id}")
    @ApiOperation(value = "司机大红包详情", notes = "修改司机大红包规则，权限：driver_special_reward_rule_detail")
    @PermissionScope(names = {"driver_special_reward_rule_detail"})
    RestResult<QuerySpecialRewardRuleDetailPresenter> getRuleDetail(@PathVariable("id") Long id) {
        return driverSpecialReward.getRuleDetail(id);
    }

    @PostMapping("/rule/{id}/random-time-give")
    @ApiOperation(value = "随机时间抽司机大红包", notes = "随机时间抽司机大红包，权限：driver_special_reward_rule_random")
    @PermissionScope(names = {"driver_special_reward_rule_random"})
    RestResult<Boolean> randomTimeGiveSpecialReward(@PathVariable("id") Long id, @Valid @RequestBody RandomTimeGiveSpecialRewardWrapper wrapper) {
        return driverSpecialReward.randomTimeGiveSpecialReward(id, wrapper);
    }

    @PostMapping("/give-driver-special-reward")
    @ApiOperation(value = "给指定司机发大红包", notes = "给指定司机发大红包，权限：driver_special_reward_rule_random_give_driver")
    @PermissionScope(names = {"driver_special_reward_rule_random_give_driver"})
    RestResult<Boolean> giveDriverSpecialReward(@Valid @RequestBody GiveDriverSpecialRewardWrapper wrapper) {
        return driverSpecialReward.giveDriverSpecialReward(wrapper);
    }

    @GetMapping("/report/rank/pick_ride")
    @ApiOperation(value = "接单排名", notes = "接单排名，权限：driver_special_reward_rule_rank_pick_ride")
    @PermissionScope(names = {"driver_special_reward_rule_rank_pick_ride"})
    RestResult<List<QuerySpecialRewardRulePickRidePresenter>> pickRideRank(QuerySpecialRewardRulePickRideWrapper wrapper) {
        return driverSpecialReward.pickRideRank(wrapper);
    }

}
